import request from '@/utils/request'
import type { AIChatSession, AIChatMessage } from '@/types/ai-chat'

// 获取AI聊天会话列表
export function getAIChatSessions() {
  return request<AIChatSession[]>({
    url: '/ai-chat/sessions',
    method: 'get'
  })
}

// 创建新会话
export function createAIChatSession(testResultId?: number) {
  return request({
    url: '/ai-chat/session',
    method: 'post',
    data: testResultId ? { testResultId } : {}
  })
}

// 获取会话消息历史
export function getAIChatMessages(sessionId: number) {
  return request<AIChatMessage[]>({
    url: `/ai-chat/messages/${sessionId}`,
    method: 'get'
  })
}

// 发送消息
export function sendAIChatMessage(data: {
  sessionId: number
  content: string
}) {
  return request<AIChatMessage>({
    url: '/ai-chat/message',
    method: 'post',
    data
  })
}

// 删除会话
export function deleteAIChatSession(sessionId: number) {
  return request({
    url: `/ai-chat/session/${sessionId}`,
    method: 'delete'
  })
}

// 重命名会话
export function renameAIChatSession(sessionId: number, title: string) {
  return request({
    url: `/ai-chat/session/${sessionId}/rename`,
    method: 'put',
    data: { title }
  })
} 